<template>
    <div>
        <h1>当前和：{{ sum }}</h1>
        <select v-model.number="n">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <button @click="increament">+</button>
        <button @click="decreament">-</button>
        <button @click="increamentOdd">当前和 是奇数才能加</button>
        <button @click="increamentWait">延迟500毫秒地加</button>
    </div>
</template>

<script>
import Vue from 'vue';
export default Vue.extend({
    name: 'Count',
    data() {
        return {
            n: 1,
            sum: 0,
        }
    },
    methods: {
        increament() {
            this.sum += this.n
        },
        decreament() {
            this.sum -= this.n
        },
        increamentOdd() {
            if (this.sum % 2) {
                this.sum += this.n
            }
        },
        increamentWait() {
            setTimeout(() => {
                this.sum += this.n
            }, 500);
        },
    }
}) 
</script>

<style>
button {
    margin: 3px;
}
</style>